﻿using MangoMes.Commont.DapperHelps;
using MangoMes.Commont.Domain.Productions;
using MangoMes.Commont.Domain.ProductionWorking;
using MangoMes.Commont.Domain.Products;
using MangoMes.Commont.DTOs;
using MangoMes.Write.API.Applications.ArrivalNotice;
using MangoMes.Write.API.Applications.Pickinges;
using MangoMes.Write.API.Applications.ProductionWrite;
using MangoMes.Write.API.Applications.ProductManaged;
using MangoMes.Write.API.Applications.ProductTyped;
using MangoMes.Write.API.Applications.Strippings;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using QRCoder;
using SkiaSharp;
//using QRCode;

namespace MangoMes.Write.API.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ProductTypeController : ControllerBase
    {
        private readonly IMediator mediator;
        private readonly IWebHostEnvironment host;

        public ProductTypeController(IMediator mediator, IWebHostEnvironment host)
        {
            this.mediator = mediator;
            this.host = host;
        }

        //第一周
        #region 物料产品分类 显示列表
        /// <summary>
        /// 物料产品分类 显示列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("ProductTypesList")]
        public async Task<ResultsDTO<ProductTypeDto>> Handle(ProductTypesSearchCommand request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 物料产品分类 新增
        /// <summary>
        /// 物料产品分类 新增
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("ProductTypesAdds")]
        public async Task<ResultsDTO> Handle(ProductTypesCreateCommand request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 物料产品分类 反填
        /// <summary>
        /// 物料产品分类 反填
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("ProductTypesEdits")]
        public async Task<ResultsDTO<ProductTypes>> Handle(ProductTypesEditCommand request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 物料产品管理 列表 
        /// <summary>
        /// 物料产品管理 列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("ProductManagesLists")]
        public async Task<PageDTO<ProductManage>> Handle(ProductManageSeachCommon request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 树形 产品分类
        /// <summary>
        /// 树形 产品分类
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("TreesList")]
        public async Task<ResultsDTO<TypeDto>> Handle(TypeListCommon request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 物料产品管理 新增 
        /// <summary>
        /// 物料产品管理 新增 
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("ProductManagesAdds")]
        public async Task<ResultsDTO> Handle(ProductManageCreateCommon request)
        {
            return await mediator.Send(request);
        }
        #endregion

        //第二周
        #region 生产领料列表 
        /// <summary>
        /// 生产领料 列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("PickingsLists")]
        public async Task<PageDTO<PickingsDto>> Handle(PickingSeachCommand? request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 生产领料 新增
        /// <summary>
        /// 生产领料 新增
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("PickingsAdds")]
        public async Task<ResultsDTO> Handle(PickingCreateCommand request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 生产领料 反填
        /// <summary>
        /// 生产领料 反填
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("PickingEdit")]
        public async Task<ResultsDTO<Picking>> Handle(PickingBackCommand request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 生产领料 修改
        /// <summary>
        /// 生产领料 修改
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("PickingUpdates")]
        public async Task<ResultsDTO> Handle(PickingUpdateCommand request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 生产退料列表
        /// <summary>
        /// 生产退料 列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("StrippingsLists")]
        public async Task<PageDTO<StrippingDto>> Handle(StrippingSeachCommand request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 生产退料 新增
        /// <summary>
        /// 生产退料 新增
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("StrippingsAdds")]
        public async Task<ResultsDTO> Handle(StrippingCreateCommand request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 生产退料 反填
        /// <summary>
        ///  生产退料 反填
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("StrippingEdits")]
        public async Task<ResultsDTO<Stripping>> Handle(StrippingBackCommand request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 生产退料 修改
        /// <summary>
        ///  生产退料 修改
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("StrippingUpdates")]
        public async Task<ResultsDTO> Handle(StrippingUpdateCommand request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 下拉框 仓库
        /// <summary>
        /// 下拉框 仓库
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("StashBindList")]
        public async Task<ResultsDTO<WarehouselistDto>> Handle(StashBindCommand request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 生产领料单行 新增
        /// <summary>
        /// 生产领料单行 新增
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("ProdlinesAdds")]
        public async Task<ResultsDTO> Handle(ProdlineCreateCommand request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 生产领料单行 列表
        /// <summary>
        /// 生产领料单行 列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("ProdlinesLists")]
        public async Task<PageDTO<ProdlineDto>> Handle(ProdlineSeachCommand request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 生产退料单行 新增
        /// <summary>
        /// 生产退料单行 新增
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("RejectionsAdds")]
        public async Task<ResultsDTO> Handle(RejectionsCreateCommand request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 生产退料单行 列表
        /// <summary>
        /// 生产退料单行 列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("RejectionsLists")]
        public async Task<PageDTO<RejectionsDto>> Handle(RejectionsSeachCommand request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 执行领出
        /// <summary>
        /// 执行领出
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("PerformPulls")]
        public async Task<ResultsDTO> Handle(PerformPullListCommand request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 执行退料
        /// <summary>
        /// 执行退料
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost("PerformStrips")]
        public async Task<ResultsDTO> CreatePerform(PerformStripListCommand cmd)
        {
            try
            {
                var cou = await mediator.Send(cmd);
                return cou;
            }
            catch (Exception)
            {
                throw;
            }
        }
        #endregion

        //第三周
        #region 到货通知单 新增
        /// <summary>
        /// 到货通知单 新增
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("ArrivalNoticesAdds")]
        public async Task<ResultsDTO> Handle(ArrivalNoticesCreateCommand request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 到货通知单 列表
        /// <summary>
        /// 到货通知单 列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("ArrivalNoticesLists")]
        public async Task<PageDTO<ArrivalNoticeDto>> Handle(ArrivalNoticesSeachCommand request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 到货通知 反填
        /// <summary>
        /// 到货通知 反填
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("ArrivalNoticesEdits")]
        public async Task<ResultsDTO<ArrivalNoticesDto>> Handle(ArrivalNoticesBackCommand request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 到货通知 修改
        /// <summary>
        /// 到货通知 修改
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("ArrivalNoticesUpdates")]
        public async Task<ResultsDTO> Handle(ArrivalNoticesUpdateCommand request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 到货通知单行 新增
        /// <summary>
        /// 到货通知单行 新增
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("NoticelinesAdds")]
        public async Task<ResultsDTO> Handle(NoticelinesCreateCommand request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 到货通知单单行 列表
        /// <summary>
        /// 到货通知单单行 列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("NoticelinesLists")]
        public async Task<PageDTO<NoticelinesDto>> Handle(NoticelinesSeachCommand request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 出库统计
        /// <summary>
        /// 出库统计
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("OutboundLists")]
        public async Task<ResultsDTO<OutboundDto>> Handle(OutboundListCommand request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 领料审批
        /// <summary>
        /// 领料审批
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("PinckingStatusAll")]
        public async Task<ResultsDTO> Handle(PickingStatusBackCommand request)
        {
            return await mediator.Send(request);
        }
        #endregion

        #region 退料审批
        /// <summary>
        /// 退料审批
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost("StrippingStatusAll")]
        public async Task<ResultsDTO> Handle(StrippingStatusBackCommand request)
        {
            return await mediator.Send(request);
        }
        #endregion

    }
}
